<?php
include_once("includes/news_function.php");
include_once("includes/global.php");
include_once("includes/smarty_config.php");
//=========================================
$id=is_numeric($_GET["id"])?$_GET['id']:die('Error');
$pagecurrent=!empty($_GET['page'])&&is_numeric($_GET['page'])?$_GET['page']:1;
//=========================================

$db->query("update ".NEWSD." set onclick=onclick+1 where nid='$id'");

useCahe("news_detail/",true);
$flag=md5($dpid.$dcid.$config["temp"].$id.$pagecurrent);
if(!$tpl->is_cached($page,$flag))
{
	
	$sql="SELECT a.*,b.con FROM ".NEWSD." a left join ".NEWSDATA." b on a.nid=b.nid WHERE a.nid='$id'";
	$db->query($sql);
	$news=$db->fetchRow();
	$tpl->assign("de",$news);
	//-------------------------------------------
	$sql_list = "select * from ".NEWSD." where ispass= 1 ";
	$db->query($sql_list);
	$article_list = $db->getRows();
	$article_id_array = array_column($article_list,'nid','nid');
	$article_title_array = array_column($article_list,'title','nid');
	if(in_array($id,$article_id_array)){
		if($id == 1){
			$prev = 0;
			$next = $id +1 ;
		} else{
			$prev = $id - 1 ;
			if(count($article_id_array) <= $id ){
				$next = 0;
			} else {
				$next =  $id + 1 ;
			}

		}
	}

	$tpl->assign('prev',$prev);
	$tpl->assign('next',$next);
	$tpl->assign('article_title_array',$article_title_array);

	//推荐
	$p_psql = "select s.*,p.pname from ".SETMEAL." s left join ".PRO." p on s.pid = p.id where s.statu like '%1%' group by s.pid order by s.id desc limit 0,4 ";
	$db->query($p_psql);
	$recomment_list = $db->getRows();
	$tpl->assign('recomment_list',$recomment_list);









	$ar1=array('[catname]','[title]','[keyword]','[des]');
	$ar2=array($news['cat'],$news['ftitle'],$news['keyboard'],strip_tags($prode['con']),$news['smalltext']);
	$config['title']=str_replace($ar1,$ar2,$config['title3']);
	$config['keyword']=str_replace($ar1,$ar2,$config['keyword3']);
	$config['description']=str_replace($ar1,$ar2,$config['description3']);
	//--------------------------------------------
	$cat_sql = "select * from ".NEWSCAT." where catid = '{$news['classid']}' ";
	$db->query($cat_sql);
	$catname = $db->fetchRow();
	$tpl->assign("catname",$catname);

	//-------------------------------------------

	$nsql = "select * from ".NEWSD." where 1 order by nid desc limit 0,5";
	$db->query($nsql);
	$new_list = $db->getRows();
	$tpl->assign('new_list',$new_list);


	$tpl->assign("current","news");
	include_once("footer.php");
	$out=tplfetch('news_detail.htm',$flag);
}
	

?>